import { getListApi } from "@/api/configCenter/warehouseEntryChannel";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formState = reactive<Partial<VolumeLimit.AddForm>>({
    name: undefined,
    channelIdList: [],
    channelName: undefined,
    rules: undefined
  });
  const loading = ref<boolean>(false);
  const formDataRef = ref<any>(null);
  const serviceOpts = ref<WarehouseEntryChannel.ListRows[]>([]);
  const getAllServiceOpts = () => {
    return getListApi({ pageNum: 1, pageSize: 99999, status: 1 } as WarehouseEntryChannel.SearchForm).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        serviceOpts.value = data.records.map((t: any) => ({ label: t.channelName, value: t.id })) || [];
      }
    });
  };
  return {
    formState,
    formDataRef,
    loading,
    serviceOpts,
    getAllServiceOpts
  };
}
